// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2005-1-4

#ifndef __CMD_HANDLER_H_SERVER_SVR_MAIN__
#define __CMD_HANDLER_H_SERVER_SVR_MAIN__

#pragma once

#include <common/netmsg/netmsg.h>
#include <common/base/utility.h>

namespace JoyServer
{

class CJoyMainUser;
class CJoyMainRoom;

class CJoyCmdHandlerBase
{
public:
    class CCommandContext
    {
    public:
        const JoyMessage::MC_Chat* m_chatMsg;
        CJoyMainUser*   m_user;
        CString m_command;
        CString m_param;
    };
    typedef void (CJoyCmdHandlerBase::*PHandlerProc)(CCommandContext& context);
    class CHandlerInfo
    {
    public:
        PHandlerProc m_pfnHandler;
        bool    m_admin;
    };
    typedef CMap<CString, const CString&, CHandlerInfo, const CHandlerInfo&> CHandlerMap;

#   define JOY_CMD_DEF(name, auth) virtual void handler_##name(CCommandContext& ) {}
#   include "cmd_def.h"
public:
    CHandlerMap     m_handlers;

public:
    CJoyCmdHandlerBase();
    virtual ~CJoyCmdHandlerBase();
};

class CJoyCmdHandler : public CJoyCmdHandlerBase
{
public:
    class CParamPair
    {
    public:
        CString m_name;
        CString m_value;
    };
    typedef CList<CParamPair>   CParamList;


    virtual void handler_kick(CCommandContext& context);
    virtual void handler_mute(CCommandContext& context);
    virtual void handler_userinfo(CCommandContext& context);
    virtual void handler_note(CCommandContext& context);
    virtual void handler_roominfo(CCommandContext& context);
    virtual void handler_kickip(CCommandContext& context);
    virtual void handler_closeroom(CCommandContext& context);
public:
    CJoyMainRoom*   m_room;
public:
    CJoyCmdHandler();
    virtual ~CJoyCmdHandler();

    virtual bool Create(CJoyMainRoom* pRoom);
    virtual void Destroy();

    bool ExtractParams(CCommandContext& context, CParamList& params);
    bool ProcessCommand(CJoyMainUser* pUser, const JoyMessage::MC_Chat* msg);
};

} // namespace JoyServer

#endif  // __CMD_HANDLER_H_SERVER_SVR_MAIN__